package com.neuedu.hcp.controller;



import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.entity.Steward;
import com.neuedu.hcp.service.IStewardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 * http://127.0.0.1:8081/steward/planList
 */
@RestController
@RequestMapping("/steward")
public class StewardController {

    @Autowired
    private IStewardService stewardService;

    /**
     *
     * @param currentPage
     * @param size
     * @param steward
     * @return
     * http://127.0.0.1:8081/hcp/steward/planList
     */
    @GetMapping("/planList")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             Steward steward){
        return stewardService.getPlanListByPage(currentPage,size,steward);
    }

    @GetMapping("/insert")
    public RespBean insert(Steward steward){
        if(stewardService.insert(steward)<=0){
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }


    @PostMapping("/update")
    public RespBean update(@RequestBody Steward steward){
        if(stewardService.updateById(steward)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer staffId){
        if(stewardService.removeById(staffId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

}
